package com.gt.andr.webbrowser;

import java.io.File;

import javax.xml.transform.TransformerException;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.os.Environment;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.webkit.WebView;

public class UserEntryHtmlActivity extends Activity {
	WebView userView;
	final String sdPath = Environment.getExternalStorageDirectory()
			.getAbsolutePath();
	final File xmlFile = new File(sdPath + "/fordynamic.xml");
	final File xsltFile = new File(sdPath + "/dynamichtmlform.xsl");

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.userwebview);
		initComponents();
		loadTransformedHtml();
	}

	private void loadTransformedHtml() {
		try {
			String htmlTransformed = XmlTransform.getTransformedHtml(xmlFile,
					xsltFile);
			userView.loadData(htmlTransformed, "text/html", "utf-8");
		} catch (TransformerException e) {
			e.printStackTrace();
		}
	}

	private void initComponents() {
		userView = (WebView) findViewById(R.id.userentrywebview);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		MenuInflater inflater = getMenuInflater();
		inflater.inflate(R.menu.savedummymenu, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		switch (item.getItemId()) {
		case R.id.saveMnuI:
			handleSave();
		}
		return true;
	}

	private void handleSave() {
		//getValues
		
		//show message
		AlertDialog.Builder builder = new AlertDialog.Builder(this);
		builder.setMessage("Save Success").setCancelable(true)
				.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int id) {
						// changeToWelcomePage();
					}

				});
		AlertDialog alert = builder.create();
		alert.show();

	}
}
